#include "stdafx.h"
#include "TriChip.h"

namespace stl
{
	IMPLEMENT_SERIAL(CTriChip, CObject, 0)

	CTriChip::CTriChip()
	{
	}

	CTriChip::CTriChip(const CPoint3D& v0, const CPoint3D& v1,
		const CPoint3D& v2, const CVector3D& nor)
	{
		m_vex[0] = v0;
		m_vex[1] = v1;
		m_vex[2] = v2;
		m_normal = nor;
	}

	CTriChip::~CTriChip()
	{
	}


	void CTriChip::Draw(COpenGLDC* pDC)
	{
		pDC->DrawTriChip(m_normal.x, m_normal.y, m_normal.z,
			m_vex[0].x, m_vex[0].y, m_vex[0].z,
			m_vex[1].x, m_vex[1].y, m_vex[1].z,
			m_vex[2].x, m_vex[2].y, m_vex[2].z);
	}

	void CTriChip::Serialize(CArchive& ar)
	{
		if (ar.IsStoring())
		{
			ar << m_normal.x << m_normal.y << m_normal.z;
			for (int i = 0; i < 3; ++i)
			{
				ar << m_vex[i].x << m_vex[i].y << m_vex[i].z;
			}
		}
		else
		{
			ar >> m_normal.x >> m_normal.y >> m_normal.z;
			for (int i = 0; i < 3; ++i)
			{
				ar >> m_vex[i].x >> m_vex[i].y >> m_vex[i].z;
			}
		}
	}

	const CTriChip& CTriChip::operator=(const CTriChip& other)
	{
		m_normal = other.m_normal;
		for (int i = 0; i < 3; ++i)
		{
			m_vex[i] = other.m_vex[i];
		}

		return *this;
	}

}


